package com.example.iwalk.newprintapplication.imp;

import com.example.iwalk.newprintapplication.inter.Operator;
import com.example.iwalk.newprintapplication.util.ESCUtil;

import java.io.UnsupportedEncodingException;

/**
 * 打印机执行者
 * Created by iwalk on 2016/12/16.
 */

public class OperatorImp implements Operator {
    private String CHARSET = "gbk";

    public OperatorImp() {
    }

    public OperatorImp(String CHARSET) {
        this.CHARSET = CHARSET;
    }

    @Override
    public byte[] sendData() {
        return generateMockData();
    }

    @Override
    public byte[] getPrinterInfo() {
        byte[] printerInfo = ESCUtil.getPrinterInfo();
        return printerInfo;
    }

    private byte[] generateMockData() {
        try {
            byte[] next2Line = ESCUtil.nextLine(2);
            byte[] title = "出餐单（午餐）**万通中心店".getBytes(CHARSET);

            byte[] boldOn = ESCUtil.boldOn();
            byte[] fontSize2Big = ESCUtil.fontSizeSetBig(3);
            byte[] center = ESCUtil.alignCenter();
            byte[] Focus = "网 507".getBytes(CHARSET);
            byte[] boldOff = ESCUtil.boldOff();
            byte[] fontSize2Small = ESCUtil.fontSizeSetSmall(3);

            byte[] left = ESCUtil.alignLeft();
            byte[] orderSerinum = "订单编号：11234".getBytes(CHARSET);
            boldOn = ESCUtil.boldOn();
            byte[] fontSize1Big = ESCUtil.fontSizeSetBig(2);
            byte[] FocusOrderContent = "韭菜鸡蛋饺子-小份（单）".getBytes(CHARSET);
            boldOff = ESCUtil.boldOff();
            byte[] fontSize1Small = ESCUtil.fontSizeSetSmall(2);

            next2Line = ESCUtil.nextLine(2);

            byte[] priceInfo = "应收:22元 优惠：2.5元 ".getBytes(CHARSET);
            byte[] nextLine = ESCUtil.nextLine(1);

            byte[] priceShouldPay = "实收:19.5元".getBytes(CHARSET);
            nextLine = ESCUtil.nextLine(1);

            byte[] takeTime = "取餐时间:2015-02-13 12:51:59".getBytes(CHARSET);
            nextLine = ESCUtil.nextLine(1);
            byte[] setOrderTime = "下单时间：2015-02-13 12:35:15".getBytes(CHARSET);

            byte[] tips_1 = "微信关注微信关注微信关注微信关注微信关注微信关注微信关注\"**\"自助下单每天免1元".getBytes(CHARSET);
            nextLine = ESCUtil.nextLine(1);
            byte[] tips_2 = "饭后点评再奖5毛".getBytes(CHARSET);
            byte[] next4Line = ESCUtil.nextLine(4);

            byte[] breakPartial = ESCUtil.feedPaperCutPartial();

//            byte[] bitmaps = draw2PxPoint(bitmap);

//            byte[] qrCode1 = ESCUtil.qrCode1("哈哈哈");
//            byte[] qrCodeStr = "哈哈哈".getBytes("GBK");
//            byte[] qrCode2 = ESCUtil.qrCode2();
//            byte[] qrCode3 = ESCUtil.qrCode3((byte) 8);
//            byte[] qrCode4 = ESCUtil.qrCode4();
            String qrdata = "哈哈哈";
            byte[] stringQR = qrdata.getBytes(CHARSET);
            int store_len = stringQR.length + 3;
            byte store_pL = (byte) (store_len % 256);
            byte store_pH = (byte) (store_len / 256);
            byte[] modelQR = ESCUtil.modelQR();
            byte[] sizeQR = ESCUtil.sizeQR(0x03);
            byte[] errorQR = ESCUtil.errorQR(0x33);
            byte[] storeQR = ESCUtil.storeQR(store_pL, store_pH);
            byte[] printQR = ESCUtil.printQR();
            byte[][] cmdBytes = {center, title, nextLine, center, boldOn, fontSize2Big, Focus, boldOff, fontSize2Small,
                    next2Line, left, orderSerinum, nextLine, center, boldOn, fontSize1Big, FocusOrderContent, boldOff,
                    fontSize1Small, nextLine, left, next2Line, priceInfo, nextLine, priceShouldPay, next2Line, takeTime,
                    nextLine, setOrderTime, next2Line, center, tips_1, nextLine, center, tips_2, next2Line,
                    next2Line, left, sizeQR, errorQR, storeQR, qrdata.getBytes(CHARSET), printQR, next4Line, breakPartial};

            return ESCUtil.byteMerger(cmdBytes);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
